package com.littleHan.brushQuestions.web.searchTopic.controller;

import com.alibaba.fastjson.JSON;
import com.littleHan.brushQuestions.common.Result;
import com.littleHan.brushQuestions.exception.FailedToLoadException;
import com.littleHan.brushQuestions.utils.GetTokenInfoUtil;
import com.littleHan.brushQuestions.web.searchTopic.pojo.vo.DicValueTopic;
import com.littleHan.brushQuestions.web.searchTopic.service.SearchTopicService;
import com.littleHan.brushQuestions.web.start.pojo.DicValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/searchTopic")
public class SearchTopicController {

    @Autowired
    private SearchTopicService searchTopicService;

    /**
     * 获取科目、题型、难度
     * @return 携带科目、题型、难度的map集合
     * @throws FailedToLoadException
     */
    @RequestMapping(value = "/getTopicObjectTypeDifficultListJ",method = RequestMethod.GET)
    public String getTopicObjectTypeDifficultList() throws FailedToLoadException {
        Map<String,Object> map=searchTopicService.getTopicObjectTypeDifficultList();
        return JSON.toJSONString(new Result().setCode(200).setMessage("获取科目题型难度成功").setData(map));
    }

    @RequestMapping(value = "/getSearchTopicListJ",method = RequestMethod.POST)
    public String getSearchTopicList(@RequestBody DicValueTopic dicValueTopic, HttpServletRequest request) throws FailedToLoadException{
        Map<String,Object> map=searchTopicService.getSearchTopicList(GetTokenInfoUtil.getUserId(request),dicValueTopic);
        return JSON.toJSONString(new Result().setCode(200).setMessage("搜索题目成功").setData(map));
    }
}
